package nix.mybatis;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import nix.mybatis.dao.UserDao;
import nix.mybatis.dao.UserDaoImpl;
import nix.mybatis.pojo.User;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

public class MyBatisDaoTest {

	private SqlSessionFactory sqlSessionFactory;

	@Before
	public void before() throws IOException {
		InputStream in = Resources.getResourceAsStream("SqlMapConfig.xml");
		this.sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
	}
	
	@Test
	public void fun1() {		
		UserDao userDao = new UserDaoImpl(sqlSessionFactory);
		User user = userDao.findById(10);
		System.out.println(user);
	}
	
	@Test
	public void fun2() {		
		UserDao userDao = new UserDaoImpl(sqlSessionFactory);
		List<User> list = userDao.findListByUsername("张");
		System.out.println(list);
	}
}
